var wApp = new Vue({
	el:"#weatherApp",
	data:{
		city:'',
		city_2:'',
		weather_list:[],
		weatherImg:[],
		xxx:''
	},
	methods:{
		tqI:function(x,y){
			if(x.type === '晴'){
				y.weatherImg.push('./Src/img/qt_i.png');
			}else if(x.type.indexOf('雨') !== -1){
				y.weatherImg.push('./Src/img/xy_i.png');
			}else if(x.type === '多云'){
				y.weatherImg.push('./Src/img/dy_i.png');
			}else if(x.type === '阴'){
				y.weatherImg.push('./Src/img/yt_i.png');
			}else if(x.indexOf("雪") !== -1){
				y.weatherImg.push('./Src/img/xx_i.png');
			}
		},
		search_n:function(){
			// console.log(this);
			if(this.city !== '' && this.city !== this.city_2){
				var that = this;
				let bd_bg = document.querySelector('body');
				axios.get('http://wthrcdn.etouch.cn/weather_mini?city=' + that.city)
					.then(function(res){
						// console.log(res.data.data.forecast);
						that.weather_list = [];
						that.weatherImg = [];								if(res.data.data.forecast.length > 4){
							for(var i = 0; i < 4; i++){
								that.weather_list.push(res.data.data.forecast[i]);
								// console.log(res.data.data.forecast[i].type);
								that.$options.methods.tqI(res.data.data.forecast[i],that);
							}
						}else{
								that.weather_list = res.data.data.forecast;
								for(var i = 0; i < that.weather_list.length; i++){
									// console.log(res.data.data.forecast[i].type);
									// that.$options.methods.tqI(res.data.data.forecast[i]);
								}
							}
						console.log(that.weatherImg);
						if(that.weather_list[0].type === '晴'){
							bd_bg.style.background = 'url(./Src/img/qt_1.gif) repeat-y scroll 0% 0% / 100vw 100vh';
						}else if(that.weather_list[0].type.indexOf('雨') !== -1){
							bd_bg.style.background = 'url(./Src/img/yu_1.gif) repeat-y scroll 0% 0% / 100vw 100vh';
						}else if(that.weather_list[0].type === '多云'){
							bd_bg.style.background = 'url(./Src/img/dy_1.gif) repeat-y scroll 0% 0% / 100vw 100vh';
						}else if(that.weather_list[0].type.indexOf("阴") !== -1 || that.weather_list[0].type.indexOf("霾") !== -1){
							bd_bg.style.background = 'url(./Src/img/yt_1.gif) repeat-y scroll 0% 0% / 100vw 100vh';
						}else if(that.weather_list[0.type.indexOf("雪") !== -1){
							bd_bg.style.background = 'url(./Src/img/xx_1.gif) repeat-y scroll 0% 0% / 100vw 100vh';
						}
					},function(err){
						console.log(err)
					})
			}			
			this.city_2 = this.city;
			// console.log(this.city);
		},
		qCity:function(c){
			this.city = c;
		}
	}
})
//天气接口一
// axios.get('http://wthrcdn.etouch.cn/weather_mini?city=' + that.city)
// 	.then(function(res){
// 		console.log(res)
// 	},function(err){
//		console.log(err)
// 	})

//天气接口二
// axios.get('https://v0.yiketianqi.com/api?version=v62&appid=82337764&appsecret=g41Nu2KP&city='+ that.city)
// 	.then(function(res){
// 		console.log(res)
// 	},function(err){
// 		console.log(err)
// 	})